from django.contrib.auth.models import AbstractUser
from django.db import models


class UserInfo(AbstractUser):
    """ 用户表 """
    phone = models.CharField(verbose_name='手机号', max_length=11)
    # REQUIRED_FIELDS = []


class Category(models.Model):
    """
    文章分类
    """
    name = models.CharField(verbose_name='分类', max_length=32)


class Article(models.Model):
    """
    文章表
    """
    status_choices = (
        (1, '发布'),
        (2, '删除'),
    )
    status = models.IntegerField(verbose_name='状态', choices=status_choices,help_text='状态', default=1)
    title = models.CharField(verbose_name='标题', max_length=32,help_text='标题')
    summary = models.CharField(verbose_name='简介', max_length=255,help_text='简介')
    # content = models.TextField(verbose_name='文章内容')
    category = models.ForeignKey(verbose_name='分类', to='Category', on_delete=models.CASCADE)

    tag = models.ManyToManyField(verbose_name='标签', to='Tag', default=5)

    comment_count = models.IntegerField(verbose_name='评论数', default=0)
    read_count = models.IntegerField(verbose_name='浏览数', default=0)

    author = models.ForeignKey(verbose_name='作者', to='UserInfo', on_delete=models.CASCADE)
    date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)


class Tag(models.Model):
    """标签"""
    title = models.CharField(verbose_name='标签', max_length=32)


class ArticleDetail(models.Model):
    article = models.OneToOneField(verbose_name='文章表', to='Article', on_delete=models.CASCADE)
    content = models.TextField(verbose_name='内容')


class Comment(models.Model):
    """ 评论表 """
    article = models.ForeignKey(verbose_name='文章', to='Article', on_delete=models.CASCADE)
    content = models.TextField(verbose_name='评论')
    user = models.ForeignKey(verbose_name='评论者', to='UserInfo', on_delete=models.CASCADE)
